<?php

namespace common\jobs;

use Yii;
use yii\console\Exception;
use common\helpers\ArrayHelper;
use SoapClient;
use open\validators\SonsoftSignatureValidator;

/**
 * 更新票务系统场馆信息
 * Class AfterMatchJob.
 */
class AfterVenueJob extends BaseRetryableJob {

    public $model = null;

    /**
     * @param \yii\queue\Queue $queue which pushed and is handling the job
     */
    public function execute($queue) {
        if (!$this->model) {
            throw new Exception('Venue is null...');
        }
        $model = $this->model;
        $wsdl = ArrayHelper::getValue(Yii::$app->params, 'sonsoft.wsdl');
        $sign = SonsoftSignatureValidator::generateSignature();
        $params = [
            'roomID' => $model->channel_id,
            'api_secret' => $sign
        ];
        $client = new SoapClient($wsdl, ['trace' => 1, 'exception' => 0]);
        $result = $client->GetVenues($params);
        $attributes = get_object_vars($result);
        $venues = ArrayHelper::getValue($attributes, 'GetVenuesResult');

        Yii::error($venues);
    }

}
